package com.hengda.museumonline.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hengda.museumonline.R;
import com.hengda.museumonline.entity.CityChengeBean;
import com.hengda.museumonline.view.AutoNextLineLinearlayout;

/**
 * @author：JFWU on 2016/9/26 18:36
 * @E-mail：jeffy12138@126.com
 */
public abstract class CityChengeAdapter<T> extends RecyclerView.Adapter {
    private Context context;
    private CityChengeBean cityChengeBean;
    private final static int TYPE_ITEM = 101;
    private final static int TYPE_FIRST = 102;

    public CityChengeAdapter(Context context, CityChengeBean cityChengeBean) {
        this.context = context;
        this.cityChengeBean = cityChengeBean;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == TYPE_ITEM) {
            View view = LayoutInflater.from(context).inflate(R.layout.citychenge_item, parent, false);
            return new ListHolder(view);
        } else {
            View view = LayoutInflater.from(context).inflate(R.layout.citychenge_first, parent, false);
            return new FirstHolder(view);
        }


    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (position == 0) {
            convert(context, holder, position);
        } else {
            convert(context, holder, position);
        }
    }

    public abstract void convert(Context mContext, RecyclerView.ViewHolder holder, int i);

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return TYPE_FIRST;
        } else {
            return TYPE_ITEM;
        }
    }

    @Override
    public int getItemCount() {
        return cityChengeBean.getData().getList().size() + 1;
    }

    public class ListHolder extends RecyclerView.ViewHolder {
        private AutoNextLineLinearlayout linearlayout;
        private TextView province;

        public AutoNextLineLinearlayout getLinearlayout() {
            return linearlayout;
        }

        public TextView getProvince() {
            return province;
        }

        public ListHolder(View itemView) {
            super(itemView);
            linearlayout = (AutoNextLineLinearlayout) itemView.findViewById(R.id.anll);
            province = (TextView) itemView.findViewById(R.id.province);

        }
    }

    public class FirstHolder extends RecyclerView.ViewHolder {
        private AutoNextLineLinearlayout linearlayout;

        public FirstHolder(View itemView) {
            super(itemView);
            linearlayout = (AutoNextLineLinearlayout) itemView.findViewById(R.id.anll);
        }

        public AutoNextLineLinearlayout getLinearlayout() {
            return linearlayout;
        }
    }
}
